﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineMovieTicket.Model;
using OnlineMovieTicket.Services;
using OnlineMovieTicket.Services.IServices;
using OnlineMovieTicket.Services.Services;

namespace OnlineMovieTicket.WebForms.BuyTicket
{
    public partial class SearchMovieTimeTable : System.Web.UI.Page
    {
        List<OnlineMovieTicket.Model.TransactionDetail> TransList = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                
                IMoviesService movieSrv = new MoviesService();
                this.ddlMovies.DataSource = movieSrv.GetMovies();
                this.ddlMovies.DataValueField = "MovieCode";
                this.ddlMovies.DataTextField = "MovieName";
                this.ddlMovies.DataBind();

                ICinemaService cinemaSrv = new CinemaService();
                this.ddlCinemas.DataSource = cinemaSrv.GetCinemas();
                this.ddlCinemas.DataValueField = "CinemaID";
                this.ddlCinemas.DataTextField = "CinemaName";
                this.ddlCinemas.DataBind();
                this.TransList = new List<TransactionDetail>();
                this.txtShowingDate.Text = DateTime.Today.ToString("dd-MMM-yyyy");
                ViewState.Add("TransList", this.TransList);        
            }
        }

        

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ITransactionService tranSrv = new TransactionService();
            TransactionDetail transDtl = new TransactionDetail();
            transDtl.cinemaId = Convert.ToInt32(this.ddlCinemas.SelectedValue);
            transDtl.MovieCode = Convert.ToInt32(this.ddlMovies.SelectedValue);
            if (!this.txtShowingDate.Text.Equals(""))
                transDtl.ShowDateTime = Convert.ToDateTime(this.txtShowingDate.Text);
            ViewState["TransList"] = tranSrv.getCinemasMovieDetail(transDtl);
        }
    }
}